import request from "@/utils/request";
// 菜单基础URL
const MENU_BASE_URL = "/api/v1/menus";

let data = [
  {
    path: "/user",
    component: "Layout",
    redirect: "/user/student",
    name: "user",
    meta: {
      title: "用户管理",
      icon: "system",
      hidden: false,
      alwaysShow: false,
      params: null,
    },
    children: [
      {
        path: "student",
        component: "user/StudentView",
        name: "student",
        meta: {
          title: "学生列表",
          icon: "el-icon-User",
          hidden: false,
          keepAlive: true,
          alwaysShow: false,
          params: null,
        },
          
      },
      {
        path: "administrator",
        component: "user/AdministratorView",
        name: "administrator",
        meta: {
          title: "管理员列表",
          icon: "role",
          hidden: false,
          keepAlive: true,
          alwaysShow: false,
          params: null,
        },
      },
      {
       path: "/user/studentadd",
        component: "user/AddView",
        meta: {
          title: "添加列表",
          hidden: true,
          keepAlive: true,
          alwaysShow: false,
          params: null,
        },
        }
      
    ],
  },
  {
    path: "/exam",
    component: "Layout",
    redirect: "/exam/examlsit",
    name: "exam",
    meta: {
      title: "卷题管理",
      icon: "tree",
      hidden: false,
      alwaysShow: false,
      params: null,
    },
    children: [
      {
        path: "/exam/examlsit",
        component: "exam/examView",
        name: "examlsit",
        meta: {
          title: "试卷列表",
          hidden: false,
          keepAlive: true,
          alwaysShow: false,
          params: null,
        },
      },
        {
        path: "/exam/TM",
        component: "exam/examTMView",
        name: "TM",
        meta: {
          title: "题目列表",
          hidden: false,
          keepAlive: true,
          alwaysShow: false,
          params: null,
        },
      },
      {
        path: "/exam/question/questionadd",
        component: "exam/edit/questionadd",
        name: "questionadd",
        meta: {
          title: "单选题添加",
          hidden: true,
          keepAlive: true,
          alwaysShow: false,
          params: null,
        },
      },
       {
        path: "/exam/question/multipleChoice",
        component: "exam/edit/MultipleChoice",
        name: "MultipleChoice",
        meta: {
          title: "多选题添加",
          hidden: true,
          keepAlive: true,
          alwaysShow: false,
          params: null,
        },
      },
        {
        path: "/exam/question/Judgment",
        component: "exam/edit/Judgmentadd",
        name: "Judgment",
        meta: {
          title: "判断题添加",
          hidden: true,
          keepAlive: true,
          alwaysShow: false,
          params: null,
        },
      },
         {
        path: "/exam/question/GapFilling",
        component: "exam/edit/GapFilling",
        name: "GapFilling",
        meta: {
          title: "判断题添加",
          hidden: true,
          keepAlive: true,
          alwaysShow: false,
          params: null,
        },
      },
         {
        path: "/exam/question/Fillinblank",
        component: "exam/edit/Fillinblank",
        name: "Fillinblank",
        meta: {
          title: "解答题添加",
          hidden: true,
          keepAlive: true,
          alwaysShow: false,
          params: null,
        },
      },
    {
        path: "/exam/question/paperadd",
        component: "exam/paperadd",
        name: "paperadd",
        meta: {
          title: "试卷添加",
          hidden: true,
          keepAlive: true,
          alwaysShow: false,
          params: null,
        },
      },
    
    ],
  },
    {
    path: "/task",
    component: "Layout",
    redirect: "/task/taskview",
    name: "/task",
    meta: {
      title: "任务管理",
      icon: "system",
      hidden: false,
      alwaysShow: false,
      params: null,
    },
    children: [
      {
        path: "taskview",
        component: "Task/TaskView",
        name: "taskview",
        meta: {
          title: "任务列表",
          icon: "el-icon-User",
          hidden: false,
          keepAlive: true,
          alwaysShow: false,
          params: null,
        },
      },
        {
        path: "cj",
        component: "Task/TaskcjView",
        name: "cj",
        meta: {
          title: "任务创建",
          icon: "el-icon-User",
          hidden: false,
          keepAlive: true,
          alwaysShow: false,
          params: null,
        },
      },
    
    ],
  },
  {
     path: "/education",
    component: "Layout",
    redirect: "/education/education1",
    name: "education",
    meta: {
      title: "教育管理",
      icon: "",
      hidden: false,
      alwaysShow: false,
      params: null,
    },
    children:[{
        path: "education1",
        component: "Education/educationView",
        name: "education1",
        meta: {
          title: "学科列表",
          icon: "",
          hidden: false,
          keepAlive: true,
          alwaysShow: false,
          params: null,
        },
      },
      {
        path: "educationadd",
        component: "Education/educationaddView",
        name: "educationadd",
        meta: {
          title: "任务添加",
          icon: "el-icon-User",
          hidden: false,
          keepAlive: true,
          alwaysShow: false,
          params: null,
        },
      }    
  ]
  },
   {
     path: "/grade",
    component: "Layout",
    redirect: "/grade/gradelist",
    name: "/grade",
    meta: {
      title: "成绩中心",
      icon: "",
      hidden: false,
      alwaysShow: false,
      params: null,
    },children:[{
        path: "gradelist",
        component: "grade/gradelistView",
        name: "gradelist",
        meta: {
          title: "答卷列表",
          icon: "",
          hidden: false,
          keepAlive: true,
          alwaysShow: false,
          params: null,
        },
      },
     

    ],
  },
  {
     path: "/message",
    component: "Layout",
    redirect: "/message/messagelsit",
    name: "/message",
    meta: {
      title: "消息中心",
      icon: "",
      hidden: false,
      alwaysShow: false,
      params: null,
    },children:[{
        path: "messagelsit",
        component: "message/messagelistView",
        name: "messagelsit",
        meta: {
          title: "消息列表",
          icon: "",
          hidden: false,
          keepAlive: true,
          alwaysShow: false,
          params: null,
        },
      },
      {
        path: "messagefasong",
        component: "message/messagefasongView",
        name: "messagefasong",
        meta: {
          title: "消息发送",
          icon: "",
          hidden: false,
          keepAlive: true,
          alwaysShow: false,
          params: null,
        },
      },

    ],
  },
    {
     path: "/log",
    component: "Layout",
    redirect: "/log/loglsit",
    name: "/log",
    meta: {
      title: "日志中心",
      icon: "",
      hidden: false,
      alwaysShow: false,
      params: null,
    },children:[{
        path: "loglsit",
        component: "logcenter/logcenterView",
        name: "loglsit",
        meta: {
          title: "用户日志",
          icon: "",
          hidden: false,
          keepAlive: true,
          alwaysShow: false,
          params: null,
        },
      },
      

    ],
  },
  
]

const MenuAPI = {
  /**
   * 获取当前用户的路由列表
   * <p/>
   * 无需传入角色，后端解析token获取角色自行判断是否拥有路由的权限
   *
   * @returns 路由列表
   */
  getRoutes() {
    return Promise.resolve<any>(data);
  },

  /**
   * 获取菜单树形列表
   *
   * @param queryParams 查询参数
   * @returns 菜单树形列表
   */
  getList(queryParams: MenuQuery) {
    return request<any, MenuVO[]>({
      url: `${MENU_BASE_URL}`,
      method: "get",
      params: queryParams,
    });
  },

  /**
   * 获取菜单下拉数据源
   *
   * @returns 菜单下拉数据源
   */
  getOptions(onlyParent?: boolean) {
    return request<any, OptionType[]>({
      url: `${MENU_BASE_URL}/options`,
      method: "get",
      params: { onlyParent: onlyParent },
    });
  },

  /**
   * 获取菜单表单数据
   *
   * @param id 菜单ID
   */
  getFormData(id: string) {
    return request<any, MenuForm>({
      url: `${MENU_BASE_URL}/${id}/form`,
      method: "get",
    });
  },

  /**
   * 添加菜单
   *
   * @param data 菜单表单数据
   * @returns 请求结果
   */
  create(data: MenuForm) {
    return request({
      url: `${MENU_BASE_URL}`,
      method: "post",
      data: data,
    });
  },

  /**
   * 修改菜单
   *
   * @param id 菜单ID
   * @param data 菜单表单数据
   * @returns 请求结果
   */
  update(id: string, data: MenuForm) {
    return request({
      url: `${MENU_BASE_URL}/${id}`,
      method: "put",
      data: data,
    });
  },

  /**
   * 删除菜单
   *
   * @param id 菜单ID
   * @returns 请求结果
   */
  deleteById(id: string) {
    return request({
      url: `${MENU_BASE_URL}/${id}`,
      method: "delete",
    });
  },
};

export default MenuAPI;

/** 菜单查询参数 */
export interface MenuQuery {
  /** 搜索关键字 */
  keywords?: string;
}

/** 菜单视图对象 */
export interface MenuVO {
  /** 子菜单 */
  children?: MenuVO[];
  /** 组件路径 */
  component?: string;
  /** ICON */
  icon?: string;
  /** 菜单ID */
  id?: string;
  /** 菜单名称 */
  name?: string;
  /** 父菜单ID */
  parentId?: string;
  /** 按钮权限标识 */
  perm?: string;
  /** 跳转路径 */
  redirect?: string;
  /** 路由名称 */
  routeName?: string;
  /** 路由相对路径 */
  routePath?: string;
  /** 菜单排序(数字越小排名越靠前) */
  sort?: number;
  /** 菜单 */
  type?: number;
  /** 菜单是否可见(1:显示;0:隐藏) */
  visible?: number;
}

/** 菜单表单对象 */
export interface MenuForm {
  /** 菜单ID */
  id?: string;
  /** 父菜单ID */
  parentId?: string;
  /** 菜单名称 */
  name?: string;
  /** 菜单是否可见(1-是 0-否) */
  visible: number;
  /** ICON */
  icon?: string;
  /** 排序 */
  sort?: number;
  /** 路由名称 */
  routeName?: string;
  /** 路由路径 */
  routePath?: string;
  /** 组件路径 */
  component?: string;
  /** 跳转路由路径 */
  redirect?: string;
  /** 菜单 */
  type?: number;
  /** 权限标识 */
  perm?: string;
  /** 【菜单】是否开启页面缓存 */
  keepAlive?: number;
  /** 【目录】只有一个子路由是否始终显示 */
  alwaysShow?: number;
  /** 参数 */
  params?: KeyValue[];
}

interface KeyValue {
  key: string;
  value: string;
}

/** RouteVO，路由对象 */
export interface RouteVO {
  /** 子路由列表 */
  children: RouteVO[];
  /** 组件路径 */
  component?: string;
  /** 路由属性 */
  meta?: Meta;
  /** 路由名称 */
  name?: string;
  /** 路由路径 */
  path?: string;
  /** 跳转链接 */
  redirect?: string;
  
}

/** Meta，路由属性 */
export interface Meta {
  /** 【目录】只有一个子路由是否始终显示 */
  alwaysShow?: boolean;
  /** 是否隐藏(true-是 false-否) */
  hidden?: boolean;
  /** ICON */
  icon?: string;
  /** 【菜单】是否开启页面缓存 */
  keepAlive?: boolean;
  /** 路由title */
  title?: string;
}
